<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改更新用户')" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m col-sm-3" id="form-user-edit" th:object="${user}">
            <input name="id" th:field="*{id}" type="hidden">
            <div class="form-group">    
                <label class="col-sm-3 control-label">用户名：</label>
                <div class="col-sm-8">
                    <input name="username" th:field="*{username}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">    
                <label class="col-sm-3 control-label">用户密码：</label>
                <div class="col-sm-8">
                    <input name="password" th:field="*{password}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">类型：</label>
                <div class="col-sm-8">
                    <select name="type" class="form-control m-b" th:with="type=${@dict.getType('lh_service_type')}" required>
                        <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{type}"></option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">测试服务器地址：</label>
                <div class="col-sm-8">
                    <input name="testAddress" th:field="*{testAddress}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">生产服务器地址：</label>
                <div class="col-sm-8">
                    <input name="prodAddress" th:field="*{prodAddress}" class="form-control" type="text" required>
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label"><a class="btn btn-primary" onclick="saveSettings()">保存</a></label>
            </div>

        </form>

    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var prefix = ctx + "lh/user";
        $("#form-user-edit").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/edit", $('#form-user-edit').serialize());
            }
        }

        function saveSettings() {
            if ($.validate.form()) {
                var config = {
                    url: prefix + "/edit",
                    type: "post",
                    dataType: "json",
                    data: $('#form-user-edit').serialize(),
                    beforeSend: function () {
                        $.modal.disable();
                    },
                    success: function(result) {
                        console.log(result);
                        if(result.code == 0) {
                            top.layer.msg("保存成功!", {
                                icon: $.modal.icon(modal_status.SUCCESS),
                                time: 2000,
                                shade: [0.1, '#8F8F8F']
                            },
                            function() {
                                $.modal.reload();
                            });
                        }
                    }
                };
                $.ajax(config);
            }
        }
    </script>
</body>
</html>